package com.demo.reentrantLock;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class End {
    //监控线程
    private Thread monitorThread;

    //启动监控线程
    public void start() {
        monitorThread = new Thread(() -> {
            Thread thread = Thread.currentThread();
            //是否被打断
            if (thread.isInterrupted()) {
                log.debug("料理后事");
                return;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                //因为sleep出现异常后 会清除打断标志
                //需要重新设置打断标志
                thread.interrupt();
            }
        }, "monitor");
        monitorThread.start();


    }

    //停止监控线程
    public void stop() {
        monitorThread.interrupt();
    }
}
